import {http} from '../../utils/http'
Page({
  data:{
    list:[],
    list1:[],
    list2:[],
    page:1,
    tag:true
  },
 async getlist(){
    let cui = await http({url:'banner/list'}).catch((err)=>err)
    // console.log(cui)
    let list = cui.data.data
    this.setData({
      list
    })
  },
  async getlist1(){
    let cui = await http({url:'cms/news/list'}).catch((err)=>err)
    console.log(cui)
    let list1 = cui.data.data
    this.setData({
      list1
    })
  },
  // shop/goods/kanjia/list
  // 监听用户上拉触底事件
  onReachBottom(){
    console.log('dsaf')
    if(!this.data.tag) return
    this.data.page+=1
    this.getlist2()
  },
  async getlist2(){
    let page = this.data.page
    let cui = await http({url:'shop/goods/list',data:{page:page, pageSize: 6 }}).catch((err)=>err)
    let list2=cui.data.data
    console.log(list2)
    if(list2.length<6){
      this.setData({
        tag:false
      })
    }
    this.setData({
      list2:this.data.list2.concat(list2)
    })
  },
  tiao(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: "/pages/renqi/renqi?id="+id
    })
  },
  // 预览图片
  previewImage(e){
    console.log(e)
    let cui = e.currentTarget.dataset.src
    let src = this.data.list.map(item=>{
      return item.picUrl
    })
    wx.previewImage({
      urls:src,
      showmenu:true,
      current:cui
    })
  },
  onLoad(){
    this.getlist()
    this.getlist1()
    this.getlist2()
  }
})